home *** CD-ROM | disk | FTP | other *** search
/ Developer CD Series 1995…tember: Reference Library / Dev.CD Sep 95 RL / Dev.CD Sep 95 RL.toast / mac / Technical Documentation / develop / develop Issue 23 code / Multipane Dialogs Code / SampleProcs.c < prev    next >
Encoding:
C/C++ Source or Header  |  1995-04-18  |  3.0 KB  |  112 lines  |  [TEXT/MMCC]

  1. #include "MPDialogs.h"
  2. #include "SampleProcs.h"
  3.  
  4. /* Sample Edit Action Procedure
  5.  *   mType : message type
  6.  *   hPtr : storage for data representing control
  7.  *   iHandle : handle if control item
  8.  *   pane : pane where the control resides
  9.  *   item : item number of control in the pane
  10.  */
  11. short MyEditAction(short mType, char *hPtr, Handle iHandle, short pane, short item)
  12. {
  13.     short ret = 0;
  14.     long val;
  15.     Str255 textStr;
  16.     
  17.     switch (mType) {
  18.         case kP2TAction: // Store value of control in memory
  19.             GetDialogItemText((Handle) iHandle, textStr);
  20.             StringToNum(textStr, &val);
  21.             *(long *) hPtr = val;
  22.             ret = sizeof(long);
  23.             break;
  24.         case kT2PAction: // Set value of control based on memory
  25.             val = *(long *) hPtr;
  26.             NumToString(val, textStr);
  27.             SetDialogItemText((Handle) iHandle, textStr);
  28.             ret = sizeof(long);
  29.             break;
  30.         case kCalcAction: // Return length of storage required
  31.             ret = sizeof(long);
  32.             break;
  33.         case kInitAction: // Initialize value
  34.             *(long *) hPtr = 0;
  35.             ret = sizeof(long);
  36.             break;
  37.         default:
  38.             break;
  39.     }
  40.  
  41.     // Return length of storage used/required (must be the same in each case).
  42.     return ret;
  43. }
  44.  
  45. /* Sample Click Action Procedure
  46.  *   mType : message type
  47.  *   dlog : dialog where control is installed
  48.  *   pane : pane where the control resides
  49.  *   item : item number of control in the pane
  50.  */
  51. short MyClickAction(short mType, DialogPtr dlog, short pane, short item)
  52. {
  53.     MPDHdl dataH;
  54.     short iType, val = 0;
  55.     Rect iRect;
  56.     Handle iHandle;
  57.     Str255 theStr;
  58.  
  59.     // Obtain multi-pane dialog state record
  60.     dataH = (MPDHdl) GetWRefCon(dlog);
  61.  
  62.     // Handle the second item validation.
  63.     if (mType == kValidateAction) {
  64.         // Validation fails if non-digits are in the field
  65.         if (pane == kCommPane && item == kFrequency + (*dataH)->baseItems) {
  66.             GetDialogItem(dlog, item, &iType, &iHandle, &iRect);
  67.             GetDialogItemText(iHandle, theStr);
  68.             val = VerifyDigits(theStr);
  69.             if (val) StopAlert(ALERT_Invalid, NULL);
  70.         }
  71.         // All other items validate a-okay
  72.         return val;
  73.     }
  74.  
  75.     // Only interested in the third checkbox now,
  76.     // so handle things the default way
  77.     if (pane != kMiscellaneousPane || item != kEnableSelfDestruct + (*dataH)->baseItems)
  78.         return (DefaultClickAction(mType, dlog, pane, item));
  79.  
  80.     // Initialize and Click messages are almost handled the same
  81.  
  82.     // Dim the third checkbox based on the value of the second
  83.     GetDialogItem(dlog, item, &iType, &iHandle, &iRect);
  84.     val = GetControlValue((ControlHandle)iHandle);
  85.     switch (mType) {
  86.         // Toggle the item in response to the user click
  87.         case kClickAction:
  88.             val = !val;
  89.             SetControlValue((ControlHandle) iHandle, val);
  90.             // Fall through!
  91.         // In either case, enable/disable next check box
  92.         case kInitAction:
  93.             AbleDItem(dlog, kSelfDestruct + (*dataH)->baseItems, val);
  94.             break;
  95.     }
  96.     
  97.     // Initialize and Click messages should never fail
  98.     return 0;
  99. }
  100.  
  101. /* Ensure the passed pascal string contains only digits.
  102.  */
  103. short VerifyDigits(StringPtr inString)
  104. {
  105.     int i;
  106.     
  107.     for(i=1; i<=*inString; i++) {
  108.         if (inString[i] < '0' || inString[i] > '9') return 1;
  109.     }
  110.     return 0;
  111. }
  112.